//
//  UIBarButtonItem + UIButton.swift
//  weibo08
//
//  Created by 陈杰明 on 16/3/3.
//  Copyright © 2016年 JM. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
    //convenience便利构造函数
    //在extension只能添加便利构造函数
    convenience init(name: String) {
        let button = UIButton()
        button.setBackgroundImage(UIImage(named: name), forState: UIControlState.Normal)
        button.setBackgroundImage(UIImage(named: "\(name)_highlighted"), forState: UIControlState.Highlighted)
        button.sizeToFit()
        
        self.init(customView: button)
    }
    //包装带按钮的BarButtonItem
    class func creatBarButtonItem(name: String) -> UIBarButtonItem{
        let button = UIButton()
        button.setBackgroundImage(UIImage(named: name), forState: UIControlState.Normal)
        button.setBackgroundImage(UIImage(named: "\(name)_highlighted"), forState: UIControlState.Highlighted)
        button.sizeToFit()
        
        return UIBarButtonItem(customView: button)
    }
    
}

